function OS_Team(host,id)
{
	this.$super=OS_Resource;
	if (this.$super(host,id)===false) return;
	delete this.$super;
	
	this.members=[];
	this.activeMemberIndex=0;
	
	this.load=function(handler)
	{
		var children=this.resourceNode.childNodes;
		for (var i=0;i<children.length;i++)
		{
			if (children[i].nodeType!=1) continue;
			if (children[i].nodeName!="member") continue;
			var child=children[i];
			var member={};
			var attributes=child.childNodes;
			for (var j=0;j<attributes.length;j++)
			{
				if (attributes[j].nodeType!=1) continue;
				var attribute=attributes[j];
				var attributeValue=attribute.childNodes[0].nodeValue;
				switch(attribute.nodeName)
				{
					case "name":
						member.name=attributeValue;
						break;
					case "appearance":
						member.appearance=eval("("+attributeValue+")");
						break;
					case "sceneActor":
						member.sceneActor=OS_Resource.resource.get(attributeValue);
						break;
					case "battler":
						member.battler=OS_Resource.resource.get(attributeValue);
						break;
					case "level":
						member.maxlevel=100;
						member.level=Number(attributeValue);
						break;
					case "initialExperience":
						member.experience=0;
						member.experienceLimit=Number(attributeValue);
						break;
					case "experienceAddition":
						member.experienceAddition=Number(attributeValue);
						break;
					case "initialHp":
						member.maxHp=Number(attributeValue);
						member.hp=member.maxHp;
						break;
					case "hpAddition":
						member.hpAddition=Number(attributeValue);
						break;
					case "initialMp":
						member.maxMp=Number(attributeValue);
						member.mp=member.maxMp;
						break;
					case "mpAddition":
						member.mpAddition=Number(attributeValue);
						break;
					case "initialSpeed":
						member.initialSpeed=Number(attributeValue);
						break;
					case "speedAddition":
						member.speedAddition=Number(attributeValue);
						break;
					case "initialAttack":
						member.initialAttack=Number(attributeValue);
						break;
					case "attackAddition":
						member.attackAddition=Number(attributeValue);
						break;
					case "initialDefense":
						member.initialDefense=Number(attributeValue);
						break;
					case "defenseAddition":
						member.defenseAddition=Number(attributeValue);
						break;
					case "initialMagic":
						member.initialMagic=Number(attributeValue);
						break;
					case "magicAddition":
						member.magicAddition=Number(attributeValue);
						break;
					case "initialResistance":
						member.initialResistance=Number(attributeValue);
						break;
					case "resistanceAddition":
						member.resistanceAddition=Number(attributeValue);
						break;
				}
			}
			this.members.push(member);
			if (!!member.appearance && this.activeMemberIndex==null)
			{
				this.activeMemberIndex=this.members.length-1;
			}
		}
		
		if (host.status.team==null)
		{
			host.status.team=this;
		}
		
		this.loaded=true;
		handler(this);
	}
	
	this.getActiveMember=function()
	{
		return this.members[this.activeMemberIndex];
	}
	
	this.nextActiveMember=function()
	{
		var index=this.activeMemberIndex+1;
		while (index!=this.activeMemberIndex)
		{
			if (index==this.members.length) index=0;
			if (!!this.members[index].appearance) break;
			index++;
		}
		this.activeMemberIndex=index;
	}
	
	this.realNumber=function()
	{
		var res=0;
		for (var i=0;i<this.members.length;i++)
		{
			if (!!this.members[i].appearance)
			{
				res++;
			}
		}
		return res;
	}
	
	//入队
	this.append=function(name)
	{
		for (var i=0;i<this.members.length;i++)
		{
			if (this.members[i].name==name)
			{
				this.members[i].appearance=true;
			}
		}
	}
	
	//离队
	this.leave=function(name)
	{
		for (var i=0;i<this.members.length;i++)
		{
			if (this.members[i].name==name)
			{
				this.members[i].appearance=false;
			}
		}
	}
	
	var needSaveList=["appearance","level","maxHp","maxMp","experience","experienceLimit"];
	this.encode=function()
	{
		var temp={};
		for (var i=0;i<this.members.length;i++)
		{
			temp[this.members[i].name]={};
			for (var j=0;j<needSaveList.length;j++)
			{
				temp[this.members[i].name][needSaveList[j]]=this.members[i][needSaveList[j]];
			};
		}
		return JSON.stringify(temp);
	}
	
	this.decode=function(data)
	{
		var temp=eval("("+data+")");
		for (var i=0;i<this.members.length;i++)
		{
			for (var j=0;j<needSaveList.length;j++)
			{
				this.members[i][needSaveList[j]]=temp[this.members[i].name][needSaveList[j]];
			};
		}
	}
}

OS_Resource.Builder.put("team",OS_Team);